<template>
	<view>
		<view v-for="item in userlist" :key="item._id">
			<view class="userbox">
				<radio @click="()=>{
					checkit(item)
				}" color="#FFCC33" :checked="item._id===activeuser._id"></radio>
				<view class="mainbox">
			
					<text>姓名：{{item.name}}</text><br>
					<text>性别：{{item.sex}}</text><br>
					<text>生日：{{item.birthday}}</text><br>
					<view style="display: flex;">手机号：<up-text  mode="phone" :text="item.phone" format="encrypt"></up-text></view><br>
				</view>
				<view class="btnbox">
					<up-text type="warning" text="修改" @click="update(item)"></up-text> <up-text type="error"  text="删除" @click="()=>{
						show=true
						activeid=item._id
					}"></up-text>
				</view>
		
			</view>
		</view>
			<view >
				<up-modal :show="show" :title="title" @cancel="()=>{
					show=false
					
				}" @confirm="()=>{
					show=false
					del(activeid)
					activeid=''
				}" :showCancelButton="true" :content='content' width='400rpx'></up-modal>
			</view>
		<button type="primary" style="width: 96%;" @click="adduser">新添用户</button>
	</view>
</template>

<script setup lang="ts">
	import {ref,onMounted} from 'vue'
	import request from "../../components/promise/promise";
	let activeuser=ref({})
	let show=ref(false)
	let activeid=ref('')
	const title = ref('删除');  
	const content = ref('是否删除该用户信息？');  
	let userlist=ref([])
	let del=async(_id:any)=>{
		console.log(_id,789898)
			await request({ url: "http://47.93.162.7/:3000/deluserlist",data:{_id:_id} })
			getuserlist()
		
	}
	
	let checkit=(item:any)=>{
		activeuser.value={...item}
		console.log(activeuser)
		uni.$emit('checkuser',activeuser.value)
	}
	let update=(item:any)=>{
		uni.setStorageSync('updateobj',JSON.stringify(item))
		uni.navigateTo({
			url:'/pages/index/update'
		})
	}
	let adduser=()=>{

		uni.navigateTo({
			url:`/pages/index/add`,
		})
	
	}
	let getuserlist = async () => {
		let { data } = await request({ url: "http://47.93.162.7:3000/getuserlist" })
		userlist.value=data.userlist
	
	}
	onMounted(() => {
		getuserlist()
		const activeobj = JSON.parse(uni.getStorageSync('activeobj'))
		activeuser.value = activeobj
	})
</script>

<style scoped>
	.mainbox{
		line-height: 50rpx;
	}
	.userbox radio{
		line-height: 100px;
		height: 100px;
		margin:0rpx 20rpx;
	}
	.btnbox :nth-child(1){
		margin: 10rpx;
	}
	.btnbox{
		display: flex;
		height: 50rpx;
		margin-left: 100rpx;
		margin-right: 50rpx;
	}
	.userbox{
		display: flex;
		padding: 20rpx 0rpx;
		background: ghostwhite;
		border-radius: 50rpx;
		width: 96%;
		/* border: 0.5px solid gray; */
		margin:20rpx auto ;
		justify-content: space-between;
	}
</style>